package com.etc.service.impl;

import java.util.List;

import com.etc.dao.impl.UserDaoImpl;
import com.etc.entity.User;
import com.etc.service.UserService;
import com.etc.util.PageData;

/**
 * UserServiceImpl
 * @author wade
 *
 */
public class UserServiceImpl implements UserService{
	UserDaoImpl dao = new UserDaoImpl();
	/**
	 * 查找所有用户
	 */
	@Override
	public List<User> getUser() {
		return dao.queryAllUser();
	}
	
    /**
     * 添加用户
     */
	@Override
	public boolean addUser(User user) {
		List<User> list=getUser();
		for (User u : list) {
			if(user.getU_name().equals(u.getU_name())) {
				return false;
			}
		}
		return dao.addUser(user);
	}
	/**
	 * 登录
	 */
	@Override
	public User userLogin(String u_name, String u_password) {
		User u =null;
		List<User> list = getUser();
		for (User user : list) {
			if(u_name.equals(user.getU_name())&&u_password.equals(user.getU_password())) {
				return user;
			}
		}
		return u;
	}
	
	/**
	 * 注册
	 */
	@Override
	public boolean register(String u_name, String u_password,String u_tel,String u_sex,String u_img) {
		return dao.register(u_name, u_password, u_tel, u_sex, u_img);
	}
	
	
	/**
	 * 验证用户名
	 */
	@Override
	public boolean userNameCheck(String u_name) {
		List<User> list = getUser();
		for (User user : list) {
			if(u_name.equals(user.getU_name())) {
				//如果为false,说明数据库中已经存在该用户名，前台应该显示 “用户名已经存在”
				return false;   
			}
		}
		return true;
	}
	
	/**
	 * 模糊查询+分页查询
	 * @param articleLike
	 * @return
	 */
	@Override
	public PageData getUserByLikeAndLimit(int pageNo, int pageSize, String titleLike) {
		// TODO Auto-generated method stub
		return dao.queryUserByLikeAndLimit(pageNo, pageSize, titleLike);
	}

	@Override
	public boolean updateUser(User user) {
		
		return dao.updateUser(user);
	}
	
	
}
